package com.apexbrain.apexbrainserver.controller;

import com.apexbrain.apexbrainserver.mapper.UserInBattleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * tb_user_in_battle表的controller
 */
@Controller
@RequestMapping("/user_in_battle")
public class UserInBattleController
{
    @Autowired
    private UserInBattleMapper userInBattleMapper;

    /**
     * 新增对战用户
     * @param user_id1 对战用户1
     * @param user_id2 对战用户2
     * @return 新增是否成功
     */
    @GetMapping("/add_user_into_battle")
    @ResponseBody
    public boolean addUserIntoBattle(@RequestParam String user_id1, @RequestParam String user_id2)
    {
        return userInBattleMapper.addUserIntoBattle("'" + user_id1 + "'", "'" + user_id2 + "'");
    }

    /**
     * 获得当前用户对战的用户
     * @param user_id 用户的用户名
     * @return 对战的对手
     */
    @GetMapping("/get_battle_user")
    @ResponseBody
    public String getBattleUser(@RequestParam String user_id)
    {
        return userInBattleMapper.getBattleUser("'" + user_id + "'");
    }

    /**
     * 删除对战用户
     * @param user_id 要删除的对战用户
     * @return 删除是否成功
     */
    @GetMapping("/remove_user")
    @ResponseBody
    public boolean removeUser(@RequestParam String user_id)
    {
        return userInBattleMapper.removeUser("'" + user_id + "'");
    }
}
